package com.well.module.user.web;

import com.github.pagehelper.PageInfo;
import com.well.kernel.spring.web.easyui.Datagrid;
import com.well.module.user.entity.User;
import com.well.module.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 用户 controller 类
 */

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "index")
    public ModelAndView index(ModelMap modelMap){
        return new ModelAndView("module/user/index",modelMap);
    }

    @RequestMapping(value = "datagrid")
    @ResponseBody
    public Datagrid<User> datagrid(User user){
        PageInfo<User> pageInfo=userService.selectPageInfo(user);
        Datagrid<User> datagrid=new Datagrid<>(pageInfo);
        return datagrid;
    }

    @RequestMapping(value = "form")
    public ModelAndView form(String id,ModelMap modelMap){
        User user=userService.select(id);
        modelMap.put("user",user);
        return new ModelAndView("module/user/form",modelMap);
    }



}
